// 二分查找，提高性能
export function binarySearch(arr, checkTarget) {
  let left = 0
  let right = arr.length - 1
  while (left <= right) {
    const mid = parseInt((right + left) / 2)
    const guess = checkTarget(arr[mid])
    if (guess === 1) {
      return mid
    } else if (guess === 0) {
      right = mid - 1
    } else {
      left = mid + 1
    }
  }
  return -1
}
